package cn.edu.zafu.bigdata.liuwenyi;

class Cube{
    private double length;
    private double width;
    private double height;

    public Cube(double length, double width, double height){
        this.length = length;
        this.width = width;
        this.height = height;
    }

    public double getLength(){
        return length;
    }

    public double getWidth(){
        return width;
    }

    public double getHeight(){
        return height;
    }

    public boolean equals(Object obj){
        if(this == obj) return true;

        if(obj == null || getClass() != obj.getClass()) return false;

        Cube other = (Cube) obj;
        return Double.compare(other.length,length) == 0 &&
                Double.compare(other.width,width) == 0 &&
                Double.compare(other.height,height) == 0;
    }
}
public class Cube_Test {
    public static void main(String[] args) {
        // 创建 Cube 对象
        Cube cube1 = new Cube(3.0, 3.0, 3.0);
        Cube cube2 = new Cube(3.0, 3.0, 3.0);
        Cube cube3 = new Cube(4.0, 4.0, 4.0);
        Cube cube4 = new Cube(3.0, 4.0, 3.0);

        // 测试相等性
        System.out.println("cube1.equals(cube2): " + cube1.equals(cube2));
        System.out.println("cube1.equals(cube3): " + cube1.equals(cube3));
        System.out.println("cube1.equals(cube4): " + cube1.equals(cube4));
        System.out.println("cube1.equals(null): " + cube1.equals(null));
        System.out.println("cube1.equals(new Object()): " + cube1.equals(new Object()));
    }

}
